#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time: 2022/9/16 0:13
# @Author: 徐洪英
# @Email: xx@gmail.com
# @File：add_contract_page.py

from selenium.webdriver.common.by import By
from config.config import HOST
from pages.base_page import BasePage
from time import sleep
class CrmAddConPage(BasePage):
    """类属性"""
    url="http://{}/crm/index.php?m=contract&a=add".format(HOST)
    business_name_locator = (By.ID, 'business_name')  # 来源商机
    business_name_click_locator = (By.XPATH, '/html/body/div[7]/div[2]/table/tbody[2]/tr/td[1]/input[1]')  # 选择商机
    business_confirm_locator = (By.XPATH, '/html/body/div[7]/div[3]/div/button[1]/span')  # ok按钮
    price_locator=(By.ID,"price") #合同金额
    contract_save_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td[2]/input[1]')  # 保存
    def click_add_con(self):
        """点击来源商机"""
        self.driver.find_element(*self.business_name_locator).click()
    def choose_add_con(self):
        """选择商机名"""
        self.driver.find_element(*self.business_name_click_locator).click()
    def click_con_ok(self):
        """点击ok键"""
        self.driver.find_element(*self.business_confirm_locator).click()
    def price_input(self,price):
        self.driver.find_element(*self.price_locator).send_keys(price)  # 查找合同金额元素
    def click_con_save(self):
        """点击保存"""
        self.driver.find_element(*self.contract_save_locator).click()
    def add_contract(self,price):
        self.click_add_con() #点击商机来源
        sleep(4)
        self.choose_add_con()#选择商机
        self.click_con_ok()#点击ok按钮
        self.price_input(price)#输入金额
        self.click_con_save()#点击保存



